<?php
$this->title='明源云客-官网管理-预约管理';
?>
    <div class="section-table mt20">    
        <div class="table-header lh30 pb5 clearfix">
            <span class="fl f14">预约用户列表</span>
            <div class="fr btn-group">
                <button class="btn" id="export-btn">导出</button>
            </div>
            <div class="fr btn-group">
                <input type="text" placeholder="姓名/电话" class="fl input-text w200 ml3 ng-pristine ng-untouched ng-valid" id="search-keyword">
                <button class="btn" id="search-btn">查询</button>
            </div>

        </div>
        <div class="mt10">
            <table  id="grid-table" width="100%" border="0" cellspacing="0" cellpadding="0" style="border:0px #DFDFDF solid"></table>
            <div id="grid-pager"></div>
        </div>
    </div>

</div></div>
<script>
$(document).ready(function() {
    $('#export-btn').bind('click', function(){
        var ids=$('#grid-table').jqGrid('getGridParam','selarrrow');
        window.location = "?r=/official/bespeak/export&ids="+ids;
    });
	$('#search-btn').bind('click', function() {
        var keyword = $('#search-keyword').val();

        $(this).attr('disabled', 'disabled');
        $('#grid-table').setGridParam(
            {
                postData: {
                    keyword: keyword
                }
            }
        );
        $('#grid-table').trigger('reloadGrid');
        $('#search-keyword').focus();
    });

    $('#search-keyword').bind('keypress', function(e) {
        if(e.keyCode == 13)
        {
            $('#search-btn').trigger('click');
            return false;
        }
        else if(e.keyCode == 27)
        {
            $('#clean-keyword-btn').trigger('click');
            $(this).val('').blur().focus();
            return false;
        }
    }).focus();
    
    $('#add-btn').bind('click', function(){window.location = "?r=/official/bespeak/edit"});
    
    $('#release-btn').bind('click', function(){
        $(this).attr('disabled', 'disabled');
        setBatch('status', 1);
        $('#grid-table').trigger('reloadGrid');
    });
    
    $('#cancel-release-btn').bind('click', function(){
        $(this).attr('disabled', 'disabled');
        setBatch('status', 0);
        $('#grid-table').trigger('reloadGrid');
    });
    
    $('#delete-btn').bind('click', function(){
        $(this).attr('disabled', 'disabled');
        setBatch('del', 1);
        $('#grid-table').trigger('reloadGrid');
    });    
    
    function setBatch (section, val) {
        var list = getList();
        $('#grid-table').setGridParam({
            postData: {
                ids: list,
                update: section,
                value: val
            }
        });          
    }

    function getList () {
        var rowData = jQuery('#grid-table').jqGrid('getGridParam','selarrrow');
        var list = "";
        if(rowData.length) {
            for(var i=0;i<rowData.length;i++){
               list += ':'+ rowData[i]; 
            }
        }
        return list;
    }

    $('#grid-table').jqGrid(
        {
            colNames: [
                '姓名',
                '电话',
                '城市',
                '公司',
                '来源',
                '创建时间',
			],
            colModel: [
                { index: 'name', name: 'name', align: 'center', width: 50 },
                { index: 'tel', name: 'tel', align: 'center', width: 50 },
                { index: 'city', name: 'city', align: 'center', width: 50 },
                { index: 'company', name: 'company', align: 'center', width: 50 },
                { index: 'source', name: 'source', align: 'center', width: 20 },
                { index: 'created_at', name: 'created_at', align: 'center', width: 40  },
            ],
            datatype: 'json',
            height: 'auto',
            autowidth: true,
			rowNum: 20,
            rowList: [1,10,20,50,100],
            viewrecords: true,
            viewsortcols: 'vertical',
			hoverrows: true,

            pager: $('#grid-pager'),
            sortname: 'id',
            sortorder: 'asc',
			multiselect: true,
            cellEdit: true,
            cellurl: '?r=/official/bespeak/quick-set',
			afterSubmitCell: function(serverresponse, rowid, cellname, value, iRow, iCol) {
				if(''!=serverresponse.responseText){
					var response = $.parseJSON(serverresponse.responseText); 
                    return [response.status,response.content];
				}else return [true];
			},
            loadComplete: function() {
                $('#search-btn').attr('disabled', false);
                $('#release-btn').attr('disabled', false);
                $('#cancel-release-btn').attr('disabled', false);
                $('#delete-btn').attr('disabled', false);
            },
            ondblClickRow: function(id) {
                //window.location.href = '?r=/official/bespeak/edit&id=' + id;
            },
            onSelectRow : function(id) {

            }
        }
    );
});

</script>